package cosc617_blackteam;

/**
 * Adds an order to the ordercollection in infoaggregator
 * @author Laura Semesky
 */
public class CmdAddOrder implements I_Command {
	
	Customer customer;
	InfoAggregator infoagg;
	MenuItem item;
	CustomerParty party;
	/**
	 * @param infoagg
	 * @param orderString - String representation of MenuItem
	 *(Because UI only gets strings it can't pass back MenuItem so passes
	 * String instead)
	 */
	public CmdAddOrder(InfoAggregator infoagg, String orderString, CustomerParty party){
		this.infoagg = infoagg;
		Menu m = infoagg.getMenu();
		this.item =  m.findMenuItem(orderString);
		this.party = party;
		//this.customer = customer;
	}
	
	/**
	 * Constructor for when the MenuItem has already been found
	 * @param infoagg
	 * @param item MenuItem ordered
	 * @param customer Customer placing the order
	 */
	public CmdAddOrder(InfoAggregator infoagg, MenuItem item, Customer customer, CustomerParty party){
		this.infoagg = infoagg;
		this.item = item;
		this.customer = customer;	
		this.party = party;
	}
	
	@Override
	public Object execute() {
		
		Order order = null;
		//checking for null because the String constructor might have not found corresponding menu item
		if(item != null && customer!= null){
			order = new Order(customer, party, item);
			infoagg.addOrder(order);
		} else if(item != null && party != null){
			order = new Order(item, party);
			infoagg.addOrder(order);
		}
		infoagg.incrementNumItemsOrdered();
		return order;
	}

}
